﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using System.Text;
using Global.Class.Library;

namespace DataTransferObject.MetaDataList
{
    public class ListAddressAreaMaster : NotifyPropertyChangeObject
    {
        private int addressAreaID;

        private DateTime entryDate;
        
        private int ancestorID;
        private int provinceID;
        private int administratorLevelID;

        private string areaCode;
        private string description;
        private string other;

        private bool leafest;
        private bool province;
        private bool district;
        private bool none;


        public ListAddressAreaMaster()
        {
            GlobalDefaultValue.Apply(this);
            this.EntryDate = DateTime.Now;
        }

        #region Properties


        [DefaultValue(-1)]
        public int AddressAreaID
        {
            get { return this.addressAreaID; }
            set { ApplyPropertyChange<ListAddressAreaMaster, int>(ref this.addressAreaID, o => o.AddressAreaID, value); }
        }

        [DefaultValue(typeof(DateTime), "01/01/1900")]
        public DateTime EntryDate
        {
            get { return this.entryDate; }
            set { ApplyPropertyChange<ListAddressAreaMaster, DateTime>(ref this.entryDate, o => o.EntryDate, value); }
        }

        [DefaultValue(0)]
        public int AncestorID
        {
            get { return this.ancestorID; }
            set { ApplyPropertyChange<ListAddressAreaMaster, int>(ref this.ancestorID, o => o.AncestorID, value); }
        }

        [DefaultValue(0)]
        public int ProvinceID
        {
            get { return this.provinceID; }
            set { ApplyPropertyChange<ListAddressAreaMaster, int>(ref this.provinceID, o => o.ProvinceID, value); }
        }

        [DefaultValue(0)]
        public int AdministratorLevelID
        {
            get { return this.administratorLevelID; }
            set { ApplyPropertyChange<ListAddressAreaMaster, int>(ref this.administratorLevelID, o => o.AdministratorLevelID, value); }
        }        

        
        [DefaultValue("")]
        public string AreaCode
        {
            get { return this.areaCode; }
            set { ApplyPropertyChange<ListAddressAreaMaster, string>(ref this.areaCode, o => o.AreaCode, value); }
        }
        
        [DefaultValue("")]
        public string Description
        {
            get { return this.description; }
            set { ApplyPropertyChange<ListAddressAreaMaster, string>(ref this.description, o => o.Description, value); }
        }


        [DefaultValue("")]
        public string Other
        {
            get { return this.other; }
            set { ApplyPropertyChange<ListAddressAreaMaster, string>(ref this.other, o => o.Other, value); }
        }


        [DefaultValue(false)]
        public bool Leafest
        {
            get { return this.leafest; }
            set { ApplyPropertyChange<ListAddressAreaMaster, bool>(ref this.leafest, o => o.Leafest, value); }
        }

        [DefaultValue(false)]
        public bool Province
        {
            get { return this.AdministratorLevelID == 1; }
            set
            {
                ApplyPropertyChange<ListAddressAreaMaster, bool>(ref this.province, o => o.Province, value);
                this.AdministratorLevelID = 1;                
            }
        }

        [DefaultValue(false)]
        public bool District
        {
            get { return this.AdministratorLevelID == 2; }
            set
            {
                ApplyPropertyChange<ListAddressAreaMaster, bool>(ref this.district, o => o.District, value);
                this.AdministratorLevelID = 2;
            }
        }


        [DefaultValue(false)]
        public bool None
        {
            get { return this.AdministratorLevelID == 0; }
            set
            {
                ApplyPropertyChange<ListAddressAreaMaster, bool>(ref this.none, o => o.None, value);
                this.AdministratorLevelID = 0;
            }
        }
                
        
        #endregion

        protected override System.Collections.Generic.List<ValidationRule> CreateRules()
        {
            List<ValidationRule> validationRules = base.CreateRules();
            validationRules.Add(new SimpleValidationRule("Description", "Reference cannot be blank.", delegate { return this.Description.Length != 0; }));
            validationRules.Add(new SimpleValidationRule("AncestorID", "Command type cannot be empty.", delegate { return (this.AncestorID == 0 || this.AncestorID != this.AddressAreaID) ; }));
            validationRules.Add(new SimpleValidationRule("ProvinceID", "Province or District.", delegate { return !(this.ProvinceID == 0 && (this.AdministratorLevelID == 1 || this.AdministratorLevelID == 2)); }));  //PROVINCE OR DISTRICT
            validationRules.Add(new SimpleValidationRule("ProvinceID", "Not Province or District.", delegate { return !(this.ProvinceID != 0 && this.AdministratorLevelID != 1 && this.AdministratorLevelID != 2); }));  //NOT PROVINCE AND NOT DISTRICT
            
            return validationRules;
        }
    }
}
